/**
 * This class represents a Traffic Control Object.
 * @author Matthew Page
 * Date: Aug 26, 2010
 * Time: 10:42:31 AM
 */
public class TrafficController {
    private int cycleNumber = 0;
    private int cycleTimer = 20;
    private int waitNumber = 0;
    private int waitTimer = 4;
    private char horState = 'G';
    private char vertState = 'R';
    private char prevGreenState = 'H';
    /**
     * Get the horizontal light state.
     * @return cycleTimer is the cycle time before the light changes.
     */
    public char getHorState() {
        return horState;
    }
    /**
     * Set the horizontal light state.
     * @param horState is the state of the horizontal light
     */
    public void setHorState(char horState) {
        this.horState = horState;
    }
   /**
     * Get the vertical light state.
     * @return char of vertState
     */
    public char getVertState() {
        return vertState;
    }
    /**
     * Set the vertical light state.
     * @param vertState is the state of the vertical light
     */
    public void setVertState(char vertState) {
        this.vertState = vertState;
    }
    /**
     * Increments the traffic cycle by 1
     */
    public void incrementCycle() {
        if (this.cycleNumber == this.cycleTimer) {
            this.horState = 'R';
            this.vertState = 'R';
            this.waitNumber++;
            if (this.waitNumber == this.waitTimer) {
                if (prevGreenState == 'H') {
                    this.vertState = 'G';
                    this.prevGreenState = 'V';
                } else {
                    this.horState = 'G';
                    this.prevGreenState = 'H';
                }
                this.waitNumber = 0;
                this.cycleNumber = 0;
            }
        } else {
            this.cycleNumber++;
        }
    }
    /**
     * Get the cycle timer.
     * @return cycleTimer is the cycle time before the light changes.
     */
    public int getCycleTimer() {
        return cycleTimer;
    }
    /**
     * Set the cycle timer.
     * @param cycleTimer is the cycle time before the light changes.
     */
    public void setCycleTimer(int cycleTimer) {
        this.cycleTimer = cycleTimer;
    }
    /**
     * Get the wait timer.
     * @return waitTimer is the cycle time that both lights stay red.
     */
    public int getWaitTimer() {
        return waitTimer;
    }
    /**
     * Set the wait timer.
     * @param waitTimer is the cycle time that both lights stay red.
     */
    public void setWaitTimer(int waitTimer) {
        this.waitTimer = waitTimer;
    }
}
